/**
 * 附体 详情页
 *
 * 作者 ganjun
 * 日期 2024-11-20 17:18:55
 */
layui.use(['jquery','febs', 'form', 'validate', 'fileUpload'], function () {
    var $ = layui.$,
        febs = layui.febs,
        layer = layui.layer,
        form = layui.form,
        fileUpload = layui.fileUpload,
        $view = $('#modelAttach-detail'),

        validate = layui.validate;

    form.verify(validate);
    form.render();
    initFormValue();


    function initFormValue() {
        if (modelAttachData) {
            form.val("modelAttach-detail-form", {
                "id": modelAttachData.id,
            });
        }

        if(modelAttachData && modelAttachData.source){
            changeSource(modelAttachData.source.toString());
        }
    }

    function changeSource(val){
        if(val === '2'){
            $('#origAttachCodeDiv').show();
        }else{
            $('#origAttachCodeDiv').hide();
        }
    }

    var fileUploadDiv = fileUpload.render({
        elem: '#fileUpload',
        url: ctx + 'upload/file',
        type: 2,//0-图片，1-视频，2-其他
        maxNum:5,
        defaultData: getFileList(),
        isDetail:true,
        done: function (res) {
        },
    });

    function getFileList() {
        if (attachs && attachs.length>0) {
            return  attachs;
        }else {
            return  [];
        }
    }

    $('#reset').click(function () {
        closeCur();
    });

    function closeCur(){
        var currentUrl = window.location.hash.replace('#', '');
        febs.view.tab.del(currentUrl);
        febs.view.tab.change("/modelAttach");
        $('#febs-modelAttach').find('#query').trigger('click');
    }
});